//购物车服务层
app.service('cartService',function($http){
	//购物车列表
	this.findCartList=function(){
		return $http.get('/cartController/findCartList.do');
	}

	//添加商品到购物车
	this.addGoodsToCartList=function(itemId,num){
		return $http.get('/cartController/addGoodsToCartList.do?itemId='+itemId+'&num='+num);
	}

	//求合计数
	this.sum=function(cartList){
		var totalValue={totalNum:0,totalMoney:0 };

		for(var i=0;i<cartList.length ;i++){
			var cart=cartList[i];//商家购物车对象
			for(var j=0;j<cart.orderItemList.length;j++){
				var orderItem=  cart.orderItemList[j];//购物明细项
				totalValue.totalNum+=orderItem.num;//累加数量
				totalValue.totalMoney+=orderItem.totalFee;//累加金额
			}
		}
		return totalValue;

	}
	//查找用户收货地址
	this.findAddressList=function(){
		return $http.get('addressController/findListByLoginUser.do');
	}

});